/// 工单模型
class RepairOrder {
  final String? id;
  final String carCode;
  final String? carType; // 车型
  final String? customerName; // 客户姓名
  final String? customerTel; // 客户电话
  final String? customerStatus; // 客户状态（在店等/不在店等）
  final String? serviceItem; // 服务项目
  final String? entryTime; // 进入门店时间
  final String? pickupTime; // 实际提车时间
  final String? paymentMethod; // 支付方式
  final double? actualAmount; // 实付金额
  final double? discountAmount; // 优惠金额
  final String? repairType; // 工单状态
  final String? totalKm;
  final String? addition;
  final String? tipCircle;
  final String? isClose;
  final String? circle;
  final String? isReaded;
  final String? owner;
  final String? insertTime;
  final String? date; // 创建日期
  final String? entershoptime; // 进店时间
  final String? wantedcompletedtime; // 预提车时间
  final String? payType; // 支付类型
  final String? saleMoney; // 销售金额
  final String? state; // 状态
  final String? customremark; // 客户备注
  final String? iswatiinginshop; // 是否在店等
  final String? contactid; // 联系人ID
  final String? ownnum; // 拥有数量
  final String? isneeddispatch; // 是否需要调度
  final String? pics; // 图片
  final String? iscommented; // 是否已评论
  final String? isfromorder; // 是否来自订单
  final String? orderid; // 订单ID
  final String? carerid; // 护理员ID
  final String? carid; // 车辆ID
  final String? nexttipkm; // 下次提醒公里数
  final String? oilvolume; // 油量
  final String? servicetype; // 服务类型
  final String? issendedsms; // 是否已发送短信
  final List<dynamic>? carinfopics; // 车辆信息图片
  final String? contact; // 联系人
  final String? repairetime; // 维修时间
  final List<dynamic>? items; // 维修项目列表

  RepairOrder({
    this.id,
    required this.carCode,
    this.carType,
    this.customerName,
    this.customerTel,
    this.customerStatus,
    this.serviceItem,
    this.entryTime,
    this.pickupTime,
    this.paymentMethod,
    this.actualAmount,
    this.discountAmount,
    this.repairType,
    this.totalKm,
    this.addition,
    this.tipCircle,
    this.isClose,
    this.circle,
    this.isReaded,
    this.owner,
    this.insertTime,
    this.date,
    this.entershoptime,
    this.wantedcompletedtime,
    this.payType,
    this.saleMoney,
    this.state,
    this.customremark,
    this.iswatiinginshop,
    this.contactid,
    this.ownnum,
    this.isneeddispatch,
    this.pics,
    this.iscommented,
    this.isfromorder,
    this.orderid,
    this.carerid,
    this.carid,
    this.nexttipkm,
    this.oilvolume,
    this.servicetype,
    this.issendedsms,
    this.carinfopics,
    this.contact,
    this.repairetime,
    this.items,
  });

  factory RepairOrder.fromJson(Map<String, dynamic> json) {
    return RepairOrder(
      id: json['_id']?.toString(),
      carCode: json['carcode']?.toString() ?? '',
      carType: json['cartype']?.toString(),
      customerName: json['name']?.toString(),
      customerTel: json['tel']?.toString(),
      customerStatus: json['customerstatus']?.toString(),
      serviceItem: json['serviceitem']?.toString(),
      entryTime: json['entrytime']?.toString(),
      pickupTime: json['pickuptime']?.toString(),
      paymentMethod: json['paymentmethod']?.toString(),
      actualAmount: json['actualamount'] != null ? double.tryParse(json['actualamount'].toString()) : null,
      discountAmount: json['discountamount'] != null ? double.tryParse(json['discountamount'].toString()) : null,
      repairType: json['repairtype']?.toString(),
      totalKm: json['totalkm']?.toString(),
      addition: json['addition']?.toString(),
      tipCircle: json['tipcircle']?.toString(),
      isClose: json['isclose']?.toString(),
      circle: json['circle']?.toString(),
      isReaded: json['isreaded']?.toString(),
      owner: json['owner']?.toString(),
      insertTime: json['inserttime']?.toString(),
      date: json['date']?.toString(),
      entershoptime: json['entershoptime']?.toString(),
      wantedcompletedtime: json['wantedcompletedtime']?.toString(),
      payType: json['payType']?.toString(),
      saleMoney: json['saleMoney']?.toString(),
      state: json['state']?.toString(),
      customremark: json['customremark']?.toString(),
      iswatiinginshop: json['iswatiinginshop']?.toString(),
      contactid: json['contactid']?.toString(),
      ownnum: json['ownnum']?.toString(),
      isneeddispatch: json['isneeddispatch']?.toString(),
      pics: json['pics']?.toString(),
      iscommented: json['iscommented']?.toString(),
      isfromorder: json['isfromorder']?.toString(),
      orderid: json['orderid']?.toString(),
      carerid: json['carerid']?.toString(),
      carid: json['carid']?.toString(),
      nexttipkm: json['nexttipkm']?.toString(),
      oilvolume: json['oilvolume']?.toString(),
      servicetype: json['servicetype']?.toString(),
      issendedsms: json['issendedsms']?.toString(),
      carinfopics: json['carinfopics'] as List<dynamic>?,
      contact: json['contact']?.toString(),
      repairetime: json['repairetime']?.toString(),
      items: json['items'] as List<dynamic>?,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      '_id': id,
      'carcode': carCode,
      'cartype': carType,
      'name': customerName,
      'tel': customerTel,
      'customerstatus': customerStatus,
      'serviceitem': serviceItem,
      'entrytime': entryTime,
      'pickuptime': pickupTime,
      'paymentmethod': paymentMethod,
      'actualamount': actualAmount,
      'discountamount': discountAmount,
      'repairtype': repairType,
      'totalkm': totalKm,
      'addition': addition,
      'tipcircle': tipCircle,
      'isclose': isClose,
      'circle': circle,
      'isreaded': isReaded,
      'owner': owner,
      'inserttime': insertTime,
      'date': date,
      'entershoptime': entershoptime,
      'wantedcompletedtime': wantedcompletedtime,
      'payType': payType,
      'saleMoney': saleMoney,
      'state': state,
      'customremark': customremark,
      'iswatiinginshop': iswatiinginshop,
      'contactid': contactid,
      'ownnum': ownnum,
      'isneeddispatch': isneeddispatch,
      'pics': pics,
      'iscommented': iscommented,
      'isfromorder': isfromorder,
      'orderid': orderid,
      'carerid': carerid,
      'carid': carid,
      'nexttipkm': nexttipkm,
      'oilvolume': oilvolume,
      'servicetype': servicetype,
      'issendedsms': issendedsms,
      'carinfopics': carinfopics,
      'contact': contact,
      'repairetime': repairetime,
      'items': items,
    };
  }
}